//R5.h

#ifndef R5_H
#define R5_H

#include <stdio.h>
#include <dos.h>


#define OPEN 0
#define CLOSED 1
#define IDLE 0
#define READING 1
#define WRITING 2

//Addresses for Com1
#define COM1_INT_ID 0x0c
#define COM1_BASE 0x3F8
#define COM1_INT_EN COM1_BASE+1
#define COM1_BRD_LSB COM1_BASE
#define COM1_BRD_MSB COM1_BASE+1
#define COM1_INT_ID_REG COM1_BASE+2
#define COM1_LC COM1_BASE+3
#define COM1_MC COM1_BASE+4
#define COM1_LS COM1_BASE+5
#define COM1_MS COM1_BASE+6
#define PIC_MASK 0x21
#define PIC_CMD 0x20
#define END_OF_INTERRUPT_CODE 0x20
#define COM1_PIC_LVL 4

#define CALCULATE_MASK(x) (1 << x)

//Addresses for Com2
#define COM2_INT_ID 0x0b
#define COM2_BASE 0x2F8
#define COM2_INT_EN COM1_BASE+1
#define COM2_BRD_LSB COM1_BASE
#define COM2_BRD_MSB COM1_BASE+1
#define COM2_INT_ID_REG COM1_BASE+2
#define COM2_LC COM1_BASE+3
#define COM2_MC COM1_BASE+4
#define COM2_LS COM1_BASE+5
#define COM2_MS COM1_BASE+6

// Interrupt Sources
#define MODEM_STATUS 0
#define OUTPUT 1
#define INPUT 2
#define LINE_STATUS 3

//Prototypes
int com_open(int *eflag_p, int baud_rate);
int com_close(void);
int com_read(char *buf_p, int *count_p);
int com_write(char *buf_p, int *count_p);
void interrupt high();
void read_in();
void write_out();


//Structs
struct device_control_block{
	int flag; 
	int *event_flag;
	int status_code;
	char *in_buff;
	int *in_count;
	int in_done;
	char *out_buff;
	int *out_count;
	int out_done;
	char ring_buffer[BUFSIZ];
	int ring_buffer_in; //tail
	int ring_buffer_out; //head
	int ring_buffer_count; 
};

typedef struct device_control_block dcb;

#endif